package com.thinker.loan.consumer.service;

import com.thinker.loan.consumer.service.processor.AmountProcessor;
import com.thinker.loan.consumer.service.processor.KycProcessor;
import com.thinker.loan.consumer.model.LoanApplicationRequest;
import com.thinker.loan.consumer.service.processor.AntiFraudProcessor;
import com.thinker.loan.consumer.service.processor.CreditCheckProcessor;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class LoanProcessingService {
    private final KycProcessor kycProcessor;
    private final AntiFraudProcessor fraudProcessor;
    private final CreditCheckProcessor creditProcessor;
    private final AmountProcessor amountProcessor;

    @PostConstruct
    public void buildChain() {
        // 体现责任链模式
        kycProcessor.setNextProcessor(fraudProcessor);
        fraudProcessor.setNextProcessor(creditProcessor);
        creditProcessor.setNextProcessor(amountProcessor);
    }

    public LoanApplicationRequest processLoan(LoanApplicationRequest request) {
        kycProcessor.processChain(request);
        return request;
    }
}
